package com.sw.study.scn.code.service.impl;

import com.sw.study.scn.code.dao.CodeDao;
import com.sw.study.scn.code.service.CodeService;
import com.sw.study.scn.pojo.AuthCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author sw
 * 业务实现
 */
@Service
public class CodeServiceImpl implements CodeService {
    @Autowired
    private CodeDao codeDao;

    @Override
    public Boolean codeSave(String email, String code) {
        AuthCode lagouAuthCode = new AuthCode();
        lagouAuthCode.setEmail(email);
        lagouAuthCode.setCode(code);
        Date date=new Date();
        Date date1=new Date(date.getTime()+10*60*1000);
        lagouAuthCode.setCreatetime(date);
        lagouAuthCode.setExpiretime(date1);
        codeDao.save(lagouAuthCode);
        return true;
    }

    @Override
    public AuthCode findOne(Example example) {

            AuthCode authCode =(AuthCode) codeDao.findOne(example).get();
            return authCode;


    }
}
